﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SaveFileDialogAdapter.cs" company="">
//   
// </copyright>
// <summary>
//   The save file dialog adapter.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Adapters
{
    using System;
    using System.Windows.Forms;

    using Libium.Core;
    using Libium.Views;

    /// <summary>
    /// The save file dialog adapter.
    /// </summary>
    public class SaveFileDialogAdapter : CommonDialogAdapter<SaveFileDialog>, ISaveFileView
    {
        #region Fields

        /// <summary>
        /// The _file path.
        /// </summary>
        private string _filePath;

        /// <summary>
        /// The _filters.
        /// </summary>
        private FileFilter[] _filters;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="SaveFileDialogAdapter"/> class.
        /// </summary>
        /// <param name="dialog">
        /// The dialog.
        /// </param>
        public SaveFileDialogAdapter(SaveFileDialog dialog)
            : base(dialog)
        {
            // TODO Add multiple file support
            // TODO Refactor modal result return
            // TODO How to implement modal via binding???
            dialog.FileOk += (s, e) =>
                {
                    _filePath = dialog.FileName;
                    FileOk();
                };
        }

        #endregion

        #region Public Events

        /// <summary>
        /// The file ok.
        /// </summary>
        public event Action FileOk;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the file name.
        /// </summary>
        public string FileName
        {
            get
            {
                return Dialog.FileName;
            }

            set
            {
                Dialog.FileName = value;
            }
        }

        /// <summary>
        /// Gets the file path.
        /// </summary>
        public string FilePath
        {
            get
            {
                return Dialog.FileName;
            }
        }

        /// <summary>
        /// Gets or sets the filter index.
        /// </summary>
        public int FilterIndex
        {
            get
            {
                return Dialog.FilterIndex;
            }

            set
            {
                Dialog.FilterIndex = value;
            }
        }

        /// <summary>
        /// Gets or sets the filters.
        /// </summary>
        public FileFilter[] Filters
        {
            get
            {
                return _filters;
            }

            set
            {
                _filters = value;
                Dialog.Filter = FileFilters.ToString(_filters);
            }
        }

        /// <summary>
        /// Gets or sets the initial directory path.
        /// </summary>
        public string InitialDirectoryPath
        {
            get
            {
                return Dialog.InitialDirectory;
            }

            set
            {
                Dialog.InitialDirectory = value;
            }
        }

        #endregion
    }
}